package com.atguigu.tingshu.order.strategy.factory;

import com.atguigu.tingshu.order.strategy.TradeDataStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class StrategyFactory {
    @Autowired
    private Map<String, TradeDataStrategy> tradeDataStrategyMap;
    /**
     * 根据策略类型获取对应策略实现类对象
     *
     * @param strategy
     * @return
     */
    public TradeDataStrategy getStrategy(String strategy) {
        if (tradeDataStrategyMap.containsKey(strategy)){
            return tradeDataStrategyMap.get(strategy);
        }
        throw new RuntimeException("策略类型不存在");
    }

}
